package Java7_Concurrency_Cookbook.thread_executor_framework.completion_service;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * @author lixiangke
 * @date 2017/11/20
 */
public class ReportGenerator implements Callable<String> {
    private String sender;
    private String title;

    public ReportGenerator(String sender, String title) {
        this.sender = sender;
        this.title = title;
    }

    @Override
    public String call() throws InterruptedException {
        long duration = (long) new Random().nextInt(10);
        System.out.printf("%s_%s: ReportGenerator: Generating a report during %d seconds\n",
                this.sender, this.title, duration);
        TimeUnit.SECONDS.sleep(duration);
        return sender + ": " + title;
    }
}
